//    Copyright (C) Kherty.  All rights reserved.

using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace OpenLS.UI
{
    partial class DialogResources
    {
        public DialogResources()
        {
            InitializeComponent();
        }
        void OnButtonClick(object sender, RoutedEventArgs args)
        {
            Button button = args.Source as Button;
            if (button == null)
                button = args.OriginalSource as Button;
            Window w = sender as Window;
            if (button == null || w == null)
                return;
            if (button.IsDefault)
            {
                w.DialogResult = true;
                w.Close();
                return;
            }
            if (button.IsCancel)
            {
                w.DialogResult = false;
                w.Close();
                return;
            }
        }
        void OnPopupButtonClick(object sender, RoutedEventArgs args)
        {
            Button button = args.Source as Button;
            if (button == null)
                button = args.OriginalSource as Button;
            Popup w = sender as Popup;
            if (button == null || w == null)
                return;
            if (button.IsDefault)
            {
                w.IsOpen = false;
                SetDialogResult(w, true);
                return;
            }
            if (button.IsCancel)
            {
                w.IsOpen = false;
                SetDialogResult(w, false);
                return;
            }
        }
        internal static DialogResources _instance = new DialogResources();


        public static bool?  GetDialogResult(DependencyObject obj)
        {
            return (bool)obj.GetValue(DialogResultProperty);
        }

        public static void SetDialogResult(DependencyObject obj, bool value)
        {
            obj.SetValue(DialogResultProperty, value);
        }

        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DialogResultProperty =
            DependencyProperty.RegisterAttached("DialogResult", typeof(bool?), typeof(DialogResources), new UIPropertyMetadata(null));



    }
}
